package tr.helper.service.jx;

import java.io.ByteArrayOutputStream;
import java.security.MessageDigest;
import java.util.Base64;
import java.util.Random;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class jiuxian {


    public static void main(String[] args) {
        String android_id = "BFE41A56-B351-4541-89E8-E0BA0D6BB29D";
        String imei = "BFE41A56-B351-4541-89E8-E0BA0D6BB29D";
        //bc3ac82dc46a597ccd8f1392bb3a6459
        String m5c = "";
        try {
            m5c = Base64.getEncoder().encodeToString(m5c(android_id));

        } catch (Exception e) {
            e.printStackTrace();
        }
        String str1 = m5c;
        String str2 = imei;
        System.out.println(encode("ANDROID" + str1 + str2));

    }

    public static byte[] DgetBytes(int i) {
        byte[] bArr = new byte[4];
        bArr[3] = (byte) (i % 256);
        int i2 = i >> 8;
        bArr[2] = (byte) (i2 % 256);
        int i3 = i2 >> 8;
        bArr[1] = (byte) (i3 % 256);
        bArr[0] = (byte) ((i3 >> 8) % 256);
        return bArr;
    }

    public static int ga(String str) {
        if (str.length() <= 0) {
            return 0;
        }
        int i = 0;
        for (char c2 : str.toCharArray()) {
            i = (i * 31) + c2;
        }
        return i;
    }


    private static byte[] m5c(String imei) throws Exception {
        String str;
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        int currentTimeMillis = (int) (System.currentTimeMillis() / 1000);
        int nextInt = new Random().nextInt();
        byte[] bytes = DgetBytes(currentTimeMillis);
        byte[] bytes2 = DgetBytes(nextInt);
        byteArrayOutputStream.write(bytes, 0, 4);
        byteArrayOutputStream.write(bytes2, 0, 4);
        byteArrayOutputStream.write(3);
        byteArrayOutputStream.write(0);
        try {
            str = imei;
        } catch (Exception unused) {
            str = "" + new Random().nextInt();
        }
        byteArrayOutputStream.write(DgetBytes(ga(str)), 0, 4);
        byteArrayOutputStream.write(DgetBytes(ga(be(byteArrayOutputStream.toByteArray()))));
        return byteArrayOutputStream.toByteArray();
    }

    public static String be(byte[] bArr) throws Exception {
        Mac instance = Mac.getInstance("HmacSHA1");
        instance.init(new SecretKeySpec(jiuxianF
            .a(new byte[]{69, 114, 116, -33, 125, -54, -31, 86, -11, 11, -78, -96, -17, -99, 64, 23, -95, -126, -82, -64, 113, 116, -16, -103, 49, -30, 9, -39, 33, -80, -68, -78, -117, 53, 30, -122,
                64, -104, 74, -49, 106, 85, -38, -93}), instance.getAlgorithm()));
        return Base64.getEncoder().encodeToString(instance.doFinal(bArr));
    }


    public static String encode(String str) {
        String str2 = "";
        try {
            MessageDigest instance = MessageDigest.getInstance("MD5");
            instance.update(str.getBytes());
            byte[] digest = instance.digest();
            for (byte b2 : digest) {
                String hexString = Integer.toHexString(b2 & 255);
                if (hexString.length() == 1) {
                    str2 = str2 + "0" + hexString;
                } else {
                    str2 = str2 + hexString;
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        return str2;

    }

}
